<?php
include_once '../samepart/header.php';
?>
<title>No.2商城-付款预览</title>

<div class="container">
    <div class="row">
        <div class=""  style=" height:100%;">
            <div class="panel panel-default"  style="margin: 0 auto;width: 95%;">
                <div class="panel-heading">
                    <h3 class="panel-title"><span class="glyphicon glyphicon-yen"></span>&nbsp;&nbsp;在线支付
                        <span class="pull-right"><a href="../order/orderList.php">返回订单列表</a>
				    	</span>
                    </h3>
                </div>
                <div class="panel-body">
                    <form  action="#" method="get">
                        <table class="table table-bordered table-striped table-hover">
                            <tr>
                                <td colspan="1">订单号:</td>
                                <td colspan="3"><input id="orderId" type="text" class="form-control" name="orderId" value="null" readonly="readonly"></td>
                            </tr>
                            <tr>
                                <td colspan="1">支付金额:</td>
                                <td colspan="3">
                                    <div class="input-group" style="width: 200px;">
                                        <input type="text" id="priceInput" class="form-control"  name="price" value="null">
                                        <div class="input-group-addon"><span class="glyphicon glyphicon-yen"></span></div>
                                    </div>
                                </td>
                            </tr>
                            <!--<tr>
                                <td colspan="1">商品介绍:</td>
                                <td colspan="3"><input type="text" class="form-control" name="body" value="xiaomi" readonly="readonly">

                                    <input type="hidden" class="form-control" name="url" value="http://localhost:8080/xiaomi/paySuccess">
                                </td>
                            </tr>-->
                        </table>
                        <div class="pull-right" style="margin-right: 30px;">
                            <input type="submit" value="确认支付" class="btn btn-warning btn-lg">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 底部 -->
<?php include_once '../samepart/footer.php' ?>
<script>
    var outTradeNo="";  //订单号
    for(var i=0;i<8;i++) //6位随机数，用以加在时间戳后面。
    {
        outTradeNo += Math.floor(Math.random()*10);
    }
    outTradeNo = new Date().getTime() + outTradeNo;  //时间戳，用来生成订单号。

    $("#priceInput").val('<?php echo $_GET["show_goodsprice"] ?>')
    $("#orderId").val(outTradeNo)
    function insertOrderDetailInfo(oid,gid,num,money){
        $.ajax({
            // async: false,//取消异步执行，为同步执行。进而被其他方法调用
            url: "http://localhost:80/phalapi/public/index.php?s=App.OrderDetail.insertOrderDetailInfo",
            type: "POST",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify({
                'order_id': oid,
                "good_id": gid,
                "goods_num": num,
                "goods_money": money,
            }),
            dataType: "JSON",
            success: function (result) {
                // uid = result['data']['userid'];

                // console.log("uid:"+uid)
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
    }



    $(function(){
        $.ajax({
            // async: false,//取消异步执行，为同步执行。进而被其他方法调用
            url: "http://localhost:80/phalapi/public/index.php?s=App.Order.insertOrderInfo",
            type: "POST",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify({
                'order_id': outTradeNo,
                "order_uaid": <?php echo $_GET["show_uaid"] ?>,
                "order_uid": <?php echo $_GET["show_uid"] ?>,
                "order_money": <?php echo $_GET["show_goodsprice"] ?>,
            }),
            dataType: "JSON",
            success: function (result) {
                uid = result['data']['userid'];

                // console.log("uid:"+uid)
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
        $.ajax({
            // async: false,//取消异步执行，为同步执行。进而被其他方法调用
            url: "http://localhost:80/phalapi/public/index.php?s=App.CartDetail.getCartDetailInfoByCid",
            type: "GET",
            contentType: "application/json;charset=utf-8",
            data: {
                "cart_id": '<?php echo $_GET["show_cid"] ?>' //uid获得当前页面的id
            },
            dataType: "JSON",
            success: function (result) {
                var cart_data = result.data.info;
                // uid = result['data']['userid'];
                for (var i = 0; i < cart_data.length; i++) {
                    // var cart_data = result.data.info;
                    var goodname_id = result.data.info[i].gid;
                    var money = result.data.info[i].money;
                    var num = result.data.info[i].num;
                    insertOrderDetailInfo(outTradeNo,goodname_id,num,money)
                }

                // console.log("uid:"+uid)
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })

        //删除添加完成后删除购物车商品
        $.ajax({
            // async: false,//取消异步执行，为同步执行。进而被其他方法调用
            url: "http://localhost:80/phalapi/public/index.php?s=App.CartDetail.deleteCartDetailInfoByCid",
            type: "POST",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify({
                "cart_id": '<?php echo $_GET["show_cid"] ?>'
            }),
            dataType: "JSON",
            success: function (result) {
                // alert("删除成功"+result.data.row)
                // console.log("uid:"+uid)
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })



    })

</script>